package com.cpos.base.mongo.service.Impl;

import com.cpos.base.mongo.entity.Order;
import com.cpos.base.mongo.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @创建人 Leiwenlong
 * @创建时间 2020/9/29
 * @描述
 **/
@Service
@Slf4j
public class OrderServiceImpl implements OrderService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void insertOrderBy(Order order) {
        mongoTemplate.insert(order,"test");
    }

    @Override
    public void deleteOrderBy(Order order) {
        mongoTemplate.remove(order);
    }

    @Override
    public void updateOrderBy(Order order) {
        mongoTemplate.update(null);
    }

    @Override
    public List<Order> findOrderBy(Order order) {
        Criteria shopName = Criteria.where("shopName").is(order.getShopName());
        Query query=new Query(shopName);
        List<Order> orders = mongoTemplate.find(query, Order.class);
        return orders;
    }
}

